#!/bin/bash 

while true
do
        echo "即将杀掉所有cube进程，请确认是否继续[yes/no]"
        read choice
        if [ $choice = "yes" ];then
                break
        else
                exit
        fi
done 
pkill -9 proc
# judge if kernel plugin exist
echo "检测vtcmd_dev 内核模块是否清除"
lsmod | grep vtcmd_dev
if test $? -ne 0; then
        echo "vtcmd_dev 模块不存在或已移除"
else
        rmmod vtcmd_dev
        echo "检测到vtcmd_dev模块，已移除"
fi

# judge if env_path does not exist
if test -z "$CUBEAPPPATH"; then
        echo "cube-tcm环境变量不存在，检查一下是不是没有在cube-tcm下执行source set_env.sh"
        exit
else
        echo "当前应用执行环境为："
        env | grep CUBEAPPPATH
fi

echo "重新安装vtcmd_dev模块"
cd $CUBEAPPPATH/vtcm_dev
make clean && make
sh load_vtcmd_dev.sh
echo "完成"

echo "启动模拟器"
if test -z "$CUBE_PATH"; then
        echo "cube-1.3环境变量不存在，检查一下是否没有在cube-1.3下执行source set_env.sh"
        exit
fi
ln -s $CUBE_PATH/proc/main/daemon_proc $CUBEAPPPATH/vtcm_netlink_emulator
cd $CUBEAPPPATH/vtcm_netlink_emulator
./daemon_proc
echo "完成"

# All finished
echo "重启完毕，可以继续执行"
